from itertools import *

def comb(x):
    ans = []
    for j in range(len(str(x))+1):
        for i in combinations(str(x),j):
            s= ''.join(i)
            if len(s) > 0:
                ans.append(int(s))
    return (ans)

def pro(n):
    if n < 2:
        return False
    for i in range(2, int(n**0.5) + 1):
        if n % i == 0:
            return False
    return True

a = int(input())
b = comb(a)
maxi = 0
if len(str(a)) == 4:
    for i in range(len(b)):
        if pro(b[i]) and str(b[i]) in str(a):
            if maxi < b[i]:
                maxi = b[i]
print(maxi)
